import axios from 'axios';
import { Menu } from '@/store/modules/menu/types';

export const MenuType = {
  MENU: '0',
  BUTTON: '1',
};

export const MENU_TYPES = [
  { label: '菜单', value: MenuType.MENU },
  { label: '按钮', value: MenuType.BUTTON },
];

export function getMenuList(): Promise<Menu[]> {
  return axios.get('/upms/menu/getMenuList');
}
/**
 * 查询单个的信息
 */
export function getMenuById(id?: string): Promise<Menu> {
  return axios.get(`/upms/menu/${id}`);
}

export function getAllMenuList(): Promise<Menu[]> {
  return axios.get('/upms/menu/getAllMenuList');
}

/**
 * 获取对应角色的权限
 */
export function getRoleMenuIds(roleId?: string): Promise<string[]> {
  return axios.get(`/upms/menu/getRoleMenuIds/${roleId}`);
}

/**
 * 添加菜单
 */
export function addMenu(data: any) {
  return axios.post('/upms/menu', data);
}

/**
 * 修改菜单
 */
export function updateMenu(data: any) {
  return axios.put('/upms/menu', data);
}

/**
 * 删除菜单
 */
export function deleteMenu(id: string) {
  return axios.delete(`/upms/menu/${id}`);
}
